package com.automannn.atm_back.codegenerate.util;

import org.apache.commons.lang.StringUtils;

import java.util.List;

/**
 * 代码字符串工具
 * @author chenkh
 * @time 2020/6/27 14:39
 */
public class CodeStringUtils {
    public CodeStringUtils() {
    }

    /**
     * 将字符数组拼接成字符串
     * @param val
     * @return
     */
    public static String append(String[] val) {
        StringBuffer sqlStr = new StringBuffer();
        String[] arr$ = val;
        int len$ = val.length;

        for(int i$ = 0; i$ < len$; ++i$) {
            String s = arr$[i$];
            if (StringUtils.isNotBlank(s)) {
                sqlStr.append(",");
                sqlStr.append("'");
                sqlStr.append(s.trim());
                sqlStr.append("'");
            }
        }

        return sqlStr.toString().substring(1);
    }

    /**
     * 首字母转小写
     * @param str
     * @return
     */
    public static String getInitialSmall(String str) {
        if (StringUtils.isNotBlank(str)) {
            str = str.substring(0, 1).toLowerCase() + str.substring(1);
        }

        return str;
    }

    /**
     * 过滤整型
     * @param t
     * @return
     */
    public static Integer filterInt(Integer t) {
        return t == null ? 0 : t;
    }

    /**
     * 判断字符串是否存在
     * @param substring
     * @param source
     * @return
     */
    public static boolean judgeIn(String substring, String[] source) {
        if (source != null && source.length != 0) {
            for(int i = 0; i < source.length; ++i) {
                String aSource = source[i];
                if (aSource.equals(substring)) {
                    return true;
                }
            }

            return false;
        } else {
            return false;
        }
    }

    /**
     * 判断字符串是否存在
     * @param substring
     * @param ls
     * @return
     */

    public static boolean judgeIn(String substring, List<String> ls) {
        String[] source = new String[0];
        if (ls != null) {
            source = (String[])((String[])ls.toArray());
        }

        if (source != null && source.length != 0) {
            for(int i = 0; i < source.length; ++i) {
                String aSource = source[i];
                if (aSource.equals(substring)) {
                    return true;
                }
            }

            return false;
        } else {
            return false;
        }
    }
}
